from sqlalchemy import Column, Integer, String, ForeignKey

from models.db import Base


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    username = Column(String(32), unique=True, index=True)
    hashed_password = Column(String(64))
    theme = Column(String(64))
    avatar = Column(String(64))
    group_id = Column(Integer, ForeignKey("groups.id"))


class Groups(Base):
    __tablename__ = "groups"

    id = Column(Integer, primary_key=True)
    name = Column(String(32), unique=True)


class Permissions(Base):
    __tablename__ = "permissions"

    id = Column(Integer, primary_key=True)
    name = Column(String(32), nullable=False, unique=True)
    parent_id = Column(Integer, ForeignKey("permissions.id"))
    description = Column(String(255))


class GroupPermissions(Base):
    __tablename__ = "group-permissions"

    id = Column(Integer, primary_key=True)
    group_id = Column(Integer, unique=True)
    permission_id = Column(Integer, unique=True)


class Blacklist(Base):
    __tablename__ = "blacklist"
    id = Column(Integer, primary_key=True)
    token = Column(String(255))
